package com.xindaoapp.henghua.db.model;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;

import com.xindaoapp.henghua.db.DaoSession;
import com.xindaoapp.henghua.entry.PropertyGatherInfo;

import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.Property;
import de.greenrobot.dao.internal.DaoConfig;

/**
 * 设备信息
 * @author chenghao
 *
 */
public class PropertyDao extends AbstractDao<PropertyGatherInfo, String> {
	public static final String TABLENAME = "property";

	public PropertyDao(DaoConfig config) {
		super(config);
	}

	public PropertyDao(DaoConfig config, DaoSession daoSession) {
		super(config, daoSession);
	}

	/**
	 * Properties of entity Note.<br/>
	 * Can be used for QueryBuilder and for referencing column names.
	 */
	public static class Properties {
		public final static Property Id = new Property(0, String.class, "id", false, "id");
		public final static Property Name = new Property(1, String.class, "name", false, "name", false);
		public final static Property Code = new Property(2, String.class, "code", false, "code", false);
		public final static Property Model = new Property(3, String.class, "model", false, "model", false);
		public final static Property Type = new Property(4, String.class, "type", false, "type", false);
		public final static Property FactoryName = new Property(5, String.class, "factory_name", false,
				"factory_name", false);
		public final static Property FactoryCode = new Property(6, String.class, "factory_code", false,
				"factory_code", false);
		public final static Property FactoryAddr = new Property(7, String.class, "factory_addr", false,
				"factory_addr", false);
		public final static Property FactoryLinkMan = new Property(8, String.class, "factory_linkman", false,
				"factory_linkman", false);
		public final static Property FactoryPhone = new Property(9, String.class, "factory_phone", false,
				"factory_phone", false);
		public final static Property SuperVisionUnitName = new Property(10, String.class,
				"supervision_unitname", false, "supervision_unitname", false);
		public final static Property SuperVisionUnitCode = new Property(11, String.class,
				"supervision_unitcode", false, "supervision_unitcode", false);
		public final static Property SuperVisionMode = new Property(12, String.class, "supervision_mode",
				false, "supervision_mode", false);
		public final static Property SuperVisionLinkMan = new Property(13, String.class,
				"supervision_linkman", false, "supervision_linkman", false);
		public final static Property IsModified = new Property(14, Integer.class, "is_modified", false,
				"is_modified", false);
	};

	/** Creates the underlying database table. */
	public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
		String constraint = ifNotExists ? "IF NOT EXISTS " : "";
		db.execSQL(String.format(
				"CREATE TABLE %s '%s' (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);",
				constraint, TABLENAME, createSqlCreate(Properties.Id), createSqlCreate(Properties.Name),
				createSqlCreate(Properties.Code), createSqlCreate(Properties.Model),
				createSqlCreate(Properties.Type), createSqlCreate(Properties.FactoryName),
				createSqlCreate(Properties.FactoryCode), createSqlCreate(Properties.FactoryAddr),
				createSqlCreate(Properties.FactoryLinkMan), createSqlCreate(Properties.FactoryPhone),
				createSqlCreate(Properties.SuperVisionUnitName),
				createSqlCreate(Properties.SuperVisionUnitCode), createSqlCreate(Properties.SuperVisionMode),
				createSqlCreate(Properties.SuperVisionLinkMan), createSqlCreate(Properties.IsModified)));
	}

	/** Drops the underlying database table. */
	public static void dropTable(SQLiteDatabase db, boolean ifExists) {
		String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'" + TABLENAME + "'";
		db.execSQL(sql);
	}

	@Override
	protected PropertyGatherInfo readEntity(Cursor cursor, int offset) {
		PropertyGatherInfo entity = new PropertyGatherInfo();
		entity.id = cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
		entity.name = cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1);
		entity.code = cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2);
		entity.model = cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3);
		entity.type = cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4);
		entity.factory_name = cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5);
		entity.factory_code = cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6);
		entity.factory_addr = cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7);
		entity.factory_linkman = cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8);
		entity.factory_phone = cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9);
		entity.supervision_unitname = cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10);
		entity.supervision_unitcode = cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11);
		entity.supervision_mode = cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12);
		entity.supervision_linkman = cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13);
		return entity;
	}

	@Override
	protected String readKey(Cursor cursor, int offset) {
		return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
	}

	@Override
	protected void readEntity(Cursor cursor, PropertyGatherInfo entity, int offset) {
		entity.id = cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
		entity.name = cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1);
		entity.code = cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2);
		entity.model = cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3);
		entity.type = cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4);
		entity.factory_name = cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5);
		entity.factory_code = cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6);
		entity.factory_addr = cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7);
		entity.factory_linkman = cursor.isNull(offset + 8) ? null : cursor.getString(offset + 8);
		entity.factory_phone = cursor.isNull(offset + 9) ? null : cursor.getString(offset + 9);
		entity.supervision_unitname = cursor.isNull(offset + 10) ? null : cursor.getString(offset + 10);
		entity.supervision_unitcode = cursor.isNull(offset + 11) ? null : cursor.getString(offset + 11);
		entity.supervision_mode = cursor.isNull(offset + 12) ? null : cursor.getString(offset + 12);
		entity.supervision_linkman = cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13);
	}

	@Override
	protected void bindValues(SQLiteStatement stmt, PropertyGatherInfo entity) {
		stmt.clearBindings();

		stmt.bindString(1, entity.id);
		stmt.bindString(2, entity.name);
		stmt.bindString(3, entity.code);
		stmt.bindString(4, entity.model);
		stmt.bindString(5, entity.type);
		stmt.bindString(6, entity.factory_name);
		stmt.bindString(7, entity.factory_code);
		stmt.bindString(8, entity.factory_addr);
		stmt.bindString(9, entity.factory_linkman);
		stmt.bindString(10, entity.factory_phone);
		stmt.bindString(11, entity.supervision_unitname);
		stmt.bindString(12, entity.supervision_unitcode);
		stmt.bindString(13, entity.supervision_mode);
		stmt.bindString(14, entity.supervision_linkman);
	}

	@Override
	protected String updateKeyAfterInsert(PropertyGatherInfo entity, long rowId) {
		return entity.id;
	}

	@Override
	protected String getKey(PropertyGatherInfo entity) {
		if (entity != null) {
			return entity.id;
		} else {
			return null;
		}
	}

	@Override
	protected boolean isEntityUpdateable() {
		return true;
	}

}
